﻿using System;
using System.IO;
using System.Linq;

using MbUnit.Framework;

namespace Abstract2ion.Tests
{
	public class DirectoryItemTestFixture : FileSystemTestFixtureBase
	{
		[Test]
		public void CanCreateDirectoryItemFromPath()
		{
			var directoryInfo = new DirectoryItem(FirstDirectoryPath);

			Assert.AreEqual(FirstDirectoryName, directoryInfo.Name);
			Assert.AreEqual(FirstDirectoryPath, directoryInfo.FullName);
		}

		[Test]
		public void CanCreateDirectoryItemFromDirectoryInfo()
		{
			var directoryInfo = new DirectoryItem(new DirectoryInfo(FirstDirectoryPath));

			Assert.AreEqual(FirstDirectoryName, directoryInfo.Name);
			Assert.AreEqual(FirstDirectoryPath, directoryInfo.FullName);
		}

		[Test]
		public void CanGetDirectories()
		{
			var directoryItem = new DirectoryItem(new DirectoryInfo(BasePath));

			var directories = directoryItem.FindDirectories();

			Assert.AreEqual(2, directories.Count());
			Assert.IsNotNull(directories.FirstOrDefault(directory => directory.Name == FirstDirectoryName));
			Assert.IsNotNull(directories.FirstOrDefault(directory => directory.Name == SecondDirectoryName));
		}

		[Test]
		public void CanGetFiles()
		{
			var directoryItem = new DirectoryItem(new DirectoryInfo(BasePath));

			var files = directoryItem.FindFiles();

			Assert.AreEqual(3, files.Count());
			Assert.IsNotNull(files.FirstOrDefault(file => file.Name == FirstFileName));
			Assert.IsNotNull(files.FirstOrDefault(file => file.Name == SecondFileName));
			Assert.IsNotNull(files.FirstOrDefault(file => file.Name == ThirdFileName));
		}

		[Test]
		public void EvaluatesExistsForValidDirectory()
		{
			var result = new DirectoryItem(FirstDirectoryPath).Exists;

			Assert.IsTrue(result);
		}

		[Test]
		public void EvaluatesExistsForInvalidDirectory()
		{
			var result = new DirectoryItem(InvalidDirectoryPath).Exists;

			Assert.IsFalse(result);
		}
	}
}